//
//  DBOptions.m
//  Recipe
//
//  Created by bing han on 12-7-4.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "DBOptions.h"
#import "BaseUrl.h"

@implementation DBOptions
static DBOptions *instence= nil;

@synthesize fmdatabase;

+(DBOptions *) newInstence{
    @synchronized(self){
        if (instence == nil) {
            instence = [[DBOptions alloc] init];
            [instence openDatabase];
        }
    }
    return instence;
}

+(id) allocWithZone:(NSZone *)zone{
    @synchronized(self){
        if (instence == nil) {
            instence = [super allocWithZone:zone];
            return instence;
        }
    }
    return nil;
}

-(id) copyWithZone:(NSZone *)zone{
    return self;
}

-(id) retain{
    return self;
}

-(unsigned) retainCount{
    return UINT_MAX;
}

-(id) autorelease{
    return self;
}

-(void) openDatabase{
    if (!fmdatabase) { 
        fmdatabase = [FMDatabase databaseWithPath:DATABASEPATH];
        [fmdatabase open];
    }
}
-(void) closeDatabase{
    if (fmdatabase) {
        instence=nil;
        [fmdatabase close];    
    }
}
@end
    
